home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2002 January / maximum-cd-2002-01.iso / Files / Mechwarrior 4 Mapping / MW4Editor.exe / content / ABLScripts / GenericScripts / Generic_PatrolRespond.abl < prev    next >
Encoding:
Text File  |  2001-07-16  |  7.3 KB  |  239 lines

  1.  
  2. //------------------------------------------------------------------
  3. // NOTE: The fsm name below MUST be changed in order for the
  4. // script to be considered a unique entity!
  5.  
  6. fsm Generic_PatrolRespond : integer;
  7.  
  8.  
  9. //------------------------------------------------------------------
  10.  
  11. // Generic_PatrolRespond:
  12. //   Follows a path.  If anything comes near, it goes off and attacks it,
  13. //   and then comes back to the path when there's nothing left to attack.
  14. //   When a specific trigger is set, it goes to another point or path
  15. //   and does the same thing.
  16.  
  17. //   I.e. this is the same as Generic_Patrol, except that it
  18. //   goes to a second point or path upon firing of a trigger.
  19.  
  20. //------------------------------------------------------------------
  21.  
  22.  
  23.  
  24. //------------------------------------------------------------------
  25. //     Constants
  26. //------------------------------------------------------------------
  27.  
  28.     const
  29.         #include_ <content\ABLScripts\mwconst.abi>
  30.  
  31. //------------------------------------------------------------------
  32. //     Types
  33. //------------------------------------------------------------------
  34.  
  35.     type
  36.         #include_ <content\ABLScripts\mwtype.abi>
  37.     
  38.  
  39. //------------------------------------------------------------------
  40. //     Variables
  41. //------------------------------------------------------------------
  42.  
  43.     var
  44.         static integer            attackRange1;        // The range at which I start attacking if in the original patrol
  45.         static integer            withdrawRange1;        // The range at which I withdraw from combat entirely
  46.         static integer            path1;                // My original path
  47.         static integer            moveType1;            // How I move along the path
  48.         static boolean            canLeavePath1;        // Can I leave the path if attacked? (TRUE by default)
  49.         static integer            speed1;                // The speed at which I move along the path
  50.  
  51.         static integer            triggerID;            // The trigger that will move me from my original patrol state to my new patrol state
  52.  
  53.         static integer            attackRange2;        // The range at which I start attacking after the trigger has fired
  54.         static integer            withdrawRange2;        // The range at which I withdraw from combat entirely
  55.         static integer            path2;                // My path after the trigger fires
  56.         static integer            moveType2;            // How I move along the second path
  57.         static boolean            canLeavePath2;        // Can I leave the second path if attacked? (TRUE by default)
  58.         static integer            speed2;                // The speed at which I move along the second path
  59.  
  60.         static integer            piloting;            // Piloting skill
  61.         static integer            gunnery;            // Gunnery skill/chance to hit
  62.         static real                minDelay;            // Minimum amount of time I will wait between shots once a weapon is reloaded
  63.         static real                maxDelay;            // Maximum amount of time I will wait between shots once a weapon is reloaded
  64.         static integer             eliteLevel;            // Elite level.  This helps determine tactics, defensive manuevers, opportunity fire
  65.                                                     // and other things.  It indicates a general level of combat experience.
  66.         static integer            attackThrottle;        // My attack throttle
  67.         static integer            findTypes;            // What kind of enemies to look for
  68.  
  69.          static integer            isShotRadius;        // How far away from me will I detect an enemy shot?
  70.  
  71.         static integer             attackSound;        // The attack sound I play when I first attack
  72.         static integer             deathSound;            // The sound I play when I die
  73.         
  74.         static integer            mood;                // My default mood.
  75.  
  76.         static integer            takeOffDistance;    // My take-off distance if I'm an airplane (ignored if not an airplane)
  77.  
  78. //------------------------------------------------------------------
  79. //     Init: my initialization function
  80. //------------------------------------------------------------------
  81.  
  82. function Init;
  83.     code
  84.         // script-specific variables
  85.         attackRange1    = 500;
  86.         withdrawRange1    = attackRange1 * 3 / 2;
  87.         path1            = -1;
  88.         moveType1        = move_circle;
  89.         canLeavePath1    = true;
  90.         speed1            = 600;
  91.  
  92.         triggerID        = 1;
  93.  
  94.         attackRange2    = 500;
  95.         withdrawRange2    = attackRange2 * 3 / 2;
  96.         path2            = -1;
  97.         moveType2        = move_circle;
  98.         canLeavePath2    = true;
  99.         speed2            = 600;
  100.  
  101.         takeOffDistance    = 150;
  102.  
  103.         // driver settings
  104.         piloting        = 50;
  105.         gunnery            = 30;
  106.         minDelay        = 1.5;
  107.         maxDelay        = 3.0;
  108.         eliteLevel        = 30;
  109.         attackThrottle    = 80;
  110.         isShotRadius    = 120;
  111.         attackSound        = -1; // no sound
  112.         deathSound        = -1; // no sound
  113.         mood            = NEUTRAL_START;
  114.         findTypes        = FT_DEFAULT;
  115.  
  116. endfunction;
  117.  
  118. //------------------------------------------------------------------
  119. //    StartState: my initial state
  120. //------------------------------------------------------------------
  121.  
  122. state StartState;
  123.  
  124.     code
  125.         SetFiringDelay            (ME,minDelay,maxDelay);
  126.         SetIgnoreFriendlyFire    (ME,true);
  127.         SetIsShotRadius            (ME,isShotRadius);
  128.         SetEntropyMood            (ME,mood);
  129.         SetCurMood                (ME,mood);
  130.         SetSkillLevel            (ME,piloting,gunnery,eliteLevel);
  131.         SetAttackThrottle        (ME,attackThrottle);
  132.                 
  133.         if (orderTakeOff(takeOffDistance) == true) then
  134.             trans FollowPath1State;
  135.         endif;
  136.  
  137. endstate;            
  138.  
  139. //------------------------------------------------------------------
  140. //    FollowPath1State: follow the original path, but keep an eye out for enemies
  141. //------------------------------------------------------------------
  142.  
  143. state FollowPath1State;
  144.     code
  145.         if (GetGlobalTrigger(triggerID)) then
  146.             trans FollowPath2State;
  147.         endif;
  148.  
  149.         if (FindEnemy(attackRange1,findTypes)) then
  150.             trans Attack1State;
  151.         endif;
  152.  
  153.         if (path1 <> -1) then
  154.             OrderMoveResumePatrol(path1,speed1,moveType1,true,false);
  155.         else
  156.             OrderMoveLookOut;
  157.         endif;
  158. endstate;
  159.  
  160. //------------------------------------------------------------------
  161. //    Attack1State: attack my current target, or return to original path if done
  162. //------------------------------------------------------------------
  163.  
  164. state Attack1State;
  165.     code
  166.         if (GetGlobalTrigger(triggerID)) then
  167.             trans Attack2State;
  168.         endif;
  169.  
  170.         if (LeaveAttackState(withdrawRange1)) then
  171.             OrderStopAttacking;
  172.             SetTarget(ME,NO_UNIT);
  173.             trans FollowPath1State;
  174.         endif;
  175.  
  176.         if (attackSound <> -1) then    
  177.             PlaySoundOnce(attackSound);
  178.         endif;
  179.  
  180.         OrderAttack(canLeavePath1);
  181.  
  182. endstate;
  183.  
  184. //------------------------------------------------------------------
  185. //    FollowPath2State: follow the second path, but keep an eye out for enemies
  186. //------------------------------------------------------------------
  187.  
  188. state FollowPath2State;
  189.     code
  190.         if (FindEnemy(attackRange2,findTypes)) then
  191.             trans Attack2State;
  192.         endif;
  193.  
  194.         if (path2 <> -1) then
  195.             OrderMoveResumePatrol(path2,speed2,moveType2,true,false);
  196.         else
  197.             OrderMoveLookOut;
  198.         endif;
  199. endstate;
  200.  
  201. //------------------------------------------------------------------
  202. //    Attack2State: attack my current target, or return to second path if done
  203. //------------------------------------------------------------------
  204.  
  205. state Attack2State;
  206.     code
  207.         if (LeaveAttackState(withdrawRange2)) then
  208.             OrderStopAttacking;
  209.             SetTarget(ME,NO_UNIT);
  210.             trans FollowPath2State;
  211.         endif;
  212.  
  213.         if (attackSound <> -1) then    
  214.             PlaySoundOnce(attackSound);
  215.         endif;
  216.  
  217.         OrderAttack(canLeavePath2);
  218.  
  219. endstate;
  220.  
  221.  
  222. //------------------------------------------------------------------
  223. //    DeadState: OK, I kicked the bucket.
  224. //------------------------------------------------------------------
  225.  
  226. state DeadState;
  227.     code
  228.         if (deathSound <> -1) then    
  229.             PlaySoundOnce(deathSound);
  230.         endif;        
  231.  
  232.         orderDie;
  233.  
  234. endstate;
  235.  
  236.  
  237. endfsm.
  238.  
  239.